_Pragma("once");

#include <sys/socket.h>
#include <cstddef>
#include <netinet/in.h>
#include <arpa/inet.h>

#include "IpAddressInfo.h"
#include "StringUtility.h"
#include "ICommunicator.h"


constexpr int DEFAULT_TIMEOUT_SECONDS = 2;

class INetwork;

class SocketCommunicator : public ICommunicator{
public:
    /** Default constructor */
    SocketCommunicator();
    /** Default destructor */
    ~SocketCommunicator();

    bool allocHandle(void) noexcept;


    bool setTimeout(INetwork& pnetwork) noexcept;

    bool setTimeout(const timeval& timeout) noexcept;


    bool connect(const IpAddressInfo& ipAddressInfo, sockaddr_in& targetIpAddress) noexcept;

    bool close() noexcept override;


    ssize_t sendRaw(const void* data, size_t length) noexcept override;

    ssize_t recvRaw(void* data, size_t length) noexcept override;


    int msocket;

protected:

};
